// 虚拟设备Api
import request from '@/config/axios'

enum Api {
  list = '/bms/fitting/list',
  add = '/bms/fitting_device/add',
  delete = '/bms/fitting_device/delete',
  batchDelete = '/bms/fitting_device/batchDelete',
  detail = '/bms/fitting_device/getDetail',
  update = '/bms/fitting_device/update',
  run = '/bms/fitting_device/run',
  set = '/bms/fitting_device/setState',
  saveDevices = '/bms/fitting_device/saveDevices',
  saveScript = '/bms/fitting_device/saveScript',
  getLogs = '/bms/fitting_device/logs/list',
}

export interface IFittingDevicesVO {
  fittings: any[]
  id: string
  assetName: string
  assetModel: string
  assetBrand: string
  assetSn: string
  deviceStatus: number
  installDate: Date
  acceptanceStatus: number
  acceptanceDate: Date
}
interface IPage {
  pageNum?: number
  pageSize?: number
}

export const getFittingDevicesList = async (data) => {
  return request.post({
    url: Api.list,
    data,
  })
}
// 删除
export const deleteFittingDevices = (data: (string | number)[]) => {
  return request.post({
    url: Api.delete,
    method: 'post',
    data,
  })
}
// 删除
export const batchDeleteFittingDevices = (data: (string | number)[]) => {
  return request.post({
    url: Api.batchDelete,
    method: 'post',
    data,
  })
}
// 编辑、保存
export const saveFittingDevices = (data: IFittingDevicesVO) => {
  return request.post({
    url: data.id ? Api.update : Api.add,
    method: 'post',
    data,
  })
}

// 获取详情
export const getFittingDevicesDetail = (fittingDeviceId) => {
  return request.get({
    url: Api.detail,
    method: 'get',
    params:{
      id: fittingDeviceId
    }
  })
}

// 手动执行
export const runVirtualDevices = (virtualDeviceId: (string | number)[]) => {
  return request.post({
    url: Api.run,
    method: 'post',
    data: {
      id: virtualDeviceId
    },
  })
}

// 保存关联设备
export const saveFittingDevicesBindDevices = (data) => {
  return request.post({
    url: Api.saveDevices,
    method: 'post',
    data,
  })
}

